package net.entelijan.cobean.bind.impl;

import net.entelijan.cobean.bind.AbstractColumnBinding;
import net.entelijan.cobean.bind.AbstractModelChangeListener;
import net.entelijan.cobean.bind.IBeanProperty;
import net.entelijan.cobean.bind.IColumn;
import net.entelijan.cobean.bind.IModelChangeListener;
import net.entelijan.cobean.bind.IRemovableFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class BoundPropertyColumnBinding extends AbstractColumnBinding<Object> {

    private static final long serialVersionUID = 1L;

    private static Log log = LogFactory.getLog(BoundPropertyColumnBinding.class);

    public IColumn createColumn() {
        return this.propertyBindingStrategy.createColumn(this);
    }

    public IModelChangeListener createModelChangeListener(IBeanProperty beanProperty, Object comp,
            IRemovableFactory removableFactory) {
        log.debug("[createBinding] beanProperty='" + beanProperty + "'");
        return new ModelChangeListener(beanProperty, comp, removableFactory);
    }

    private static class ModelChangeListener extends AbstractModelChangeListener<Object, Object> {

        public ModelChangeListener(IBeanProperty beanProperty, Object comp,
                IRemovableFactory removableFactory) {
            super(beanProperty, comp, removableFactory);
        }

        @Override
        public void setComponentValue(Object value) {
            log.debug("[setValue] bind the beans of the collections value='" + value + "'");
            // TODO Check how a cobean can be made repaintable. Eventually all cobeans get a repaint method in an ICobean Interface.
            //this.component.repaint();
        }

    }

}
